Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Removed locks && ensure everything runs on JS Thread #25164

Closed
wants to merge 3 commits into from

Conversation

zhongwuzw
Copy link
Contributor

Summary

Before, we add the lock to prevent race condition, it would happen because there has two threads can access concurrently, main thread and JS Thread, actually, most of the time, only JS Thread would call it, and main thread would access it only when app state changed, like in/out background.

Now, we only need to dispatch operations to JS Thread when app state changed, then we can remove all locks. Timer module is time sensitive, so I think remove locks is better. :)

Changelog

[iOS] [Enhancement] - Removed locks && ensure everything runs on JS Thread

Test Plan

CI passed.

@zhongwuzw zhongwuzw requested a review from shergin as a code owner June 6, 2019 04:17
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 6, 2019
@pull-bot
Copy link

pull-bot commented Jun 6, 2019

Messages
📖

📋 Verify Changelog Format - A changelog entry has the following format: [CATEGORY] [TYPE] - Message.

CATEGORY may be:
  • General
  • iOS
  • Android
  • JavaScript
  • Internal (for changes that do not need to be called out in the release notes)

TYPE may be:

  • Added, for new features.
  • Changed, for changes in existing functionality.
  • Deprecated, for soon-to-be removed features.
  • Removed, for now removed features.
  • Fixed, for any bug fixes.
  • Security, in case of vulnerabilities.

MESSAGE may answer "what and why" on a feature level. Use this to briefly tell React Native users about notable changes.

Generated by 🚫 dangerJS against 277f708

@react-native-bot react-native-bot added the Platform: iOS iOS applications. label Jun 6, 2019
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sammy-SC has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

}

// Called from main thread
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use RCTAssertMainQueue() (and co) instead of comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shergin 🤔 Emm, actually, these two method can be called on any threads, because we always dispatch work to JS Thread via dispatchBlock:queue. Should we need to add it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the comments. We allow it to be called on any thread. :)

@@ -171,28 +171,35 @@ - (dispatch_queue_t)methodQueue
return RCTJSThread;
}

// Called from JS Thread.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned that it's always true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 For the old module system, seems we use this rule to do things, for example : https://github.com/facebook/react-native/blob/master/React/Modules/RCTUIManager.m#L97-L101,

.... , but yeah TM may change it which call invalidate always on JS Thread. I'll add an dispatch here. :)

@zhongwuzw zhongwuzw requested review from sammy-SC and facebook-github-bot and removed request for facebook-github-bot June 25, 2019 08:39
Copy link
Contributor

@shergin shergin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which exact problem are we solving here?
Are there any real threading issue or so?

Acquiring a non-contagious lock is probably the most efficient (fast) synchronization primitive, so the existing variant is way more efficient than
scheduling a block.

@zhongwuzw
Copy link
Contributor Author

@shergin Yes, it has, more info please see #23674, #21211 (comment), the thread issue may happened when app go into background, open a dialog or something, the reason is we add the notification to observe app state, and its handler would be called on main thread, but we need to put all things to JS thread. Scheduling the block to JS thread only happened in cases like app goes into background, it's the rare case, most of the time, for the app running in foreground, we always timing on JS thread, not need any locks.

@github-actions
Copy link

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 12, 2023
@github-actions
Copy link

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants